package com.example.learn.controller;

import com.example.learn.entity.Statistical;

import com.example.learn.entity.User;

import com.example.learn.service.StatisticalService;
import com.example.learn.token.CurrentUser;
import com.example.learn.token.UserLoginToken;
import com.example.learn.utile.Response.BaseResponse;
import com.example.learn.utile.Response.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/statistical")
public class StatisticalController {
    @Autowired
    StatisticalService statisticalService;

    @UserLoginToken
    @RequestMapping(value = "getstatistical",method = RequestMethod.GET)
    public BaseResponse getstatistical(@RequestParam Boolean isfamily, @CurrentUser User user){
        List<Statistical> incomeList=      statisticalService.getstatistical(isfamily,user);
        return new ObjectRestResponse().data(incomeList);
    }

    @UserLoginToken
    @RequestMapping(value = "addstatistical",method = RequestMethod.POST)
    public BaseResponse addstatistical(@RequestBody Statistical statistical , @CurrentUser User user){
        String incomeStr=      statisticalService.addstatistical(statistical,user);
        return new ObjectRestResponse().data(incomeStr);
    }

    @RequestMapping(value = "deletestatistical",method = RequestMethod.POST)
    public BaseResponse deletestatistical(String id){
        String incomeStr=      statisticalService.deletestatistical(id);
        return new ObjectRestResponse().data(incomeStr);
    }
}
